using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ornament.MemberShip;
using Ornament.Messages;
using Ornament.MVCWebFrame.Models;
using Ornament.Web.ModelBinder;
using Products.Databases;

namespace Ornament.MVCWebFrame
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute("Product", "product/{action}/{id}/{version}",
                                new
                                {
                                    controller = "product",
                                    id = UrlParameter.Optional,
                                    version = UrlParameter.Optional
                                });
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                );
            routes.MapRoute("workList",
                            "Messages/Works/{pageSize}/{pageIndex}/{state}/{template}",
                            new
                                {
                                    Controller = "Messages",
                                    action = "Works",
                                    pageSize = 40,
                                    pageIndex = 0,
                                    template = "default",
                                    state = ReadState.UnRead
                                }
                );
        }

        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();
            AreaRegistration.RegisterAllAreas();
            ModelBinders.Binders.Add(typeof(User), new UserBinder());
            ModelBinders.Binders.Add(typeof(UserGroup), new UserGroupBinder());
            ModelBinders.Binders.Add(typeof(Table), new TableBinder());
            ModelBinders.Binders.Add(typeof(Field), new FieldBinder());
            ModelBinders.Binders.Add(typeof(FieldSnapshot), new FieldSnapshotBinder());

            RegisterRoutes(RouteTable.Routes);
        }
    }
}